<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品收银</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
	<link rel="shortcut icon" href="favicon.ico">
	<link href="${ctxStatic}/plugins/h+/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
	<%--<link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">--%>
	<link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
	<link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
	<link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<!--[if lt IE 8]>
    <!-- Data Tables -->
    <link href="${ctxStatic}/plugins/h+/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
	<!--新增css-->
    <link href="${ctxStatic}/xmarket/css/newplus.css" rel="stylesheet">
	
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>if(window.top !== window.self){ window.top.location = window.location;}
    
  
    </script>
	<style>
		/******开始:弹出*********/
		.somediv{
			text-align:center;
		}
		.autofildin{
			width: 240px !important;
			margin: 20px auto;
			border-radius: 50px !important;
			text-align:center;
		}
		.midgoods {
			min-height: 200px;
		}
		.moremenusff{
			margin-top: 15px;
		}
		.moremenus {
			margin-top: 15px;
		}
		.payway_icons{
			text-align:right;
		}
		.payway_icons a{
			margin:0 10px;
		}
		.col-orange{
			color:#fe6b04;
		}
		.sometext{
			margin:10px auto;
			font-size:14px;
		}
		.otherbtmshow{
			position:fixed;
			bottom:0;
			width:100%;
			top: inherit;
			background-color: #fff;
			margin:0 auto;
			padding-bottom:20px;
			padding-top:20px;
		}
		/******结束:弹出*********/

		.newhomeplus{
			width:100%;
		}
		.saleTJ{
			padding:0 15px 0;
		}
		.saleTJ .saleTJlie{
			background-color:#42bef7;
			color:#fff;
			padding:16px 0;
			font-size:12px;
			border-radius:4px;
		}
		.saleTJlie div p{
			margin:0;
		}
		.saleTJlie div p.num{
			font-size:28px;
		}
		.saleTJlie div img{
			margin-top:2px;
		}
		.saleSel{
			margin:14px 0;
		}
		table.TJtable{
			width:48%;
			margin:1%;
			float:left;
			background-color:#fff;
			border:1px solid #e7e8e9;
			color:#000;
			font-size:14px;
		}
		table.TJtable tr td.bg{
			background-color:#f7f7f7;
			width:50%;
		}
		table.TJtable tr td{
			border:1px solid #e7e8e9;
			padding:8px 15px;
		}
		.padding0{
			padding:0;
		}
		.toplabel{
			padding-left:15px;
		}
		.padding07{
			padding:0 7px;
		}
		.topselect{
			width:200px;
			display:inline-block;
			margin-left:40px;
		}
		#gift_img{
			width:140px;
			height:140px;
			border:1px solid #eee;
		}
		#gift_img canvas{
			width:140px;
			height: 140px;
			position: relative;
			left: -15px;
		}
	</style>
</head>

<body class="gray-bg" onload="winopen()">
	<div class="row border-bottom">
		<nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
			<div class="navbar-header" style="width: 40%;">
				<a class="navbar-minimalize minimalize-styl-2a " href="javascript:;">
					<img src="${ctxStatic}/xmarket/img/jl_logo.png" />
				</a>
				<div class="navbar-form-custom nav-name-longwidth">
					<div class="jl-logoright-name">
						<div class="logoright-name-big">辽宁线下体验店</div>
						<div class="logoright-name-small">辽宁线下体验店</div>
					</div>
				</div>
			</div>
			<ul class="nav navbar-top-links navbar-right">
				<li class="hidden-xs">
					<div class="payway_icons">
						<label class="paytext" style="margin-top: 6px;">本店已开通：</label>
						<div style="float:right;">
							<a href="javascript:;" class="payway-yzf"></a>
							<a href="javascript:;" class="payway-wx"></a>
							<a href="javascript:;" class="payway-zfb"></a>
						</div>
					</div>
				</li>
				<li class="hidden-xs">
					<a href="javascript:;" id="launch" style="display: block" onclick="launchFullscreen(document.documentElement);" class="J_menuItem" data-index="0"><i class="fa fa-th-large"></i>全屏</a>
					<a href="javascript:;" id="exit" style="display: none" onclick="exitFullscreen(document);" class="J_menuItem" data-index="0"><i class="fa fa-th-large"></i>退出全屏</a>
				</li>
				<li class="hidden-xs">
					<a href="javascript:;" onclick="payCash();" class="J_menuItem" data-index="0"><i class="fa fa-exchange"></i>收银</a>
				</li>
				<li class="hidden-xs">
					<a href="javascript:;" onclick="logout();" class="J_menuItem" data-index="0"><i class="fa fa-sign-out"></i> 注销</a>
				</li>
			</ul>
		</nav>
	</div>
	
	<div class="ibox float-e-margins">
		<div class="ibox-title newtitle_height">
			<div style="margin-top:8px;float:left;">
				<div class="form-group">
					<label class="col-sm-4 control-label">商品编码：</label>
					<div class="col-sm-8" style="margin-top:-8px;">
						<input type="text" id="thisCode" placeholder="编码" class="form-control" >
						<script type="text/javascript">
							window.onload = function()
							{
								document.getElementById("thisCode").focus();
							}
						</script>
					</div>
				</div>
			</div> 
			<div class="ibox-tools">
				<a href="javascript:;" class="toolfloat">发券</a>
				<select class="form-control m-b" name="account" style="width:200px;" id="user_code">
					<c:if test="${mapUser.return_code == 1}">
						<c:choose>
							<c:when test="${not empty mapUser.return_data }">
								<c:forEach items="${mapUser.return_data}" var="obj" varStatus="vs">
									<option value="${obj.user_code}">${obj.person_name}</option>
								</c:forEach>
							</c:when>
						</c:choose>
					</c:if>
					<c:if test="${mapUser.return_code == 0}">
						<option value="-1">导购员</option>
					</c:if>
				</select>
			</div>
		</div>
	</div>
	
	<div class="row">
		<div class="col-sm-12 ibox-content midgoods">
			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th>商品编码</th>
						<th>商品名称</th>
						<th>规格</th>
						<th>单位</th>
						<th>单价(券点)</th>
						<th>数量</th>
						<th>合计(券点)</th>
						<th>删除</th>
					</tr>
				</thead>
				<tbody id="goodsBody">
				</tbody>
			</table>
		</div>
		<div class="col-sm-12 confpay">
			<div class="col-sm-6">
				<div class="">订单合计券点：<span id="totalPay">0.00</span></div>
				<div class="">收银员：辽宁线下体验店</div>
			</div>
			<div class="col-sm-6 text-right">
				<a class="btn btn-jlorange" onclick="doPay();" href="javascript:;">确认收银</a>
			</div>
		</div>
		<div class="col-sm-12 confpay">
			<div class="col-sm-6 text-right">
				<a class="btn btn-jlorange" onclick="showother();" href="javascript:;">更多</a>
			</div>
		</div>
	</div>


	<!--底部弹出-->
		<div class="othermore otherbtmshow modal inmodal fade" id="other" tabindex="-1" role="dialog"  aria-hidden="true" >
			<div class="">
				<div class="modal-header" style="padding: 0 15px;">
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
					</button>
				</div>
				<div class="row moremenusff">
					<div class="col-sm-3"><a href="javascript:;" target="_self" onclick="toMoeny();" class="more-menus-a more-checkrecord"></a>收银记录</div>
					<div class="col-sm-3"><a href="javascript:;" target="_self" class="more-menus-a more-printset"></a>打印机设置</div>
					<div class="col-sm-3"><a href="javascript:;" target="_self" class="more-menus-a more-cashier" onclick="toClerk()"></a>收银员管理</div>
					<div class="col-sm-3"><a href="javascript:;" target="_self" class="more-menus-a more-printticket" onclick="toReceipt()"></a>补打小票</div>
				</div>
				<div class="row moremenus">
					<div class="col-sm-3"><a href="javascript:;" target="_self" class="more-menus-b more-exeset" onclick="toSumInfo()"></a>销售统计</div>
					<div class="col-sm-3"><a href="javascript:;" target="_self" onclick="toQuan();" class="more-menus-b more-getqrecord"></a>领券记录</div>
					<div class="col-sm-3"><a href="javascript:;" target="_self" onclick="showPWDChangePopup();" class="more-menus-b more-changepsw"></a>修改密码</div>
					<div class="col-sm-3"><a href="javascript:;" target="_self" onclick="showAbout90Popup();"  class="more-menus-b more-aboutjl"></a>关于久零</div>
				</div>
			</div>
		</div>
	<!--弹出 -->
	<div class="modal inmodal fade" id="somethingpop" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-md">
			<div class="modal-content">
				<div class="modal-body somediv">
					<img src="${ctxStatic}/xmarket/img/popma.png" width="120px"/>
					<div class="sometext">
						请扫描客户手机<span class="col-orange">久零券付款码，或者手机号</span>
					</div>
					<input type="text" class="form-control autofildin" id="someinput" placeholder=""  onkeyup="phoneValidate()">
					<div class="text-right">
						<label><input type="checkbox" class="i-checks" id="isBicheckbox" onclick="doCheckThis(this);" checked="checked">优先使用久零贝</label>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" onclick="ValidateUser()">确定</button>
					<button type="button" class="btn btn-white" onclick="doCancel()" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>


	<!--弹出付款页面 -->
	<div class="modal inmodal fade" id="somethingpop_payOrder" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-md">
			<div class="modal-content">
				<div class="modal-body somediv">
					<img src="${ctxStatic}/xmarket/img/popma.png" width="120px"/>
					<div class="sometext">
						90贝消费<span style="color:#3A5FCD">0</span>元
						&nbsp;&nbsp;&nbsp;&nbsp;
						任需支付<span id="needMoney" style="color:#FF0000" >0</span>元
					</div>
					<div class="sometext">
						请扫描客户手机支付条码
					</div>
					<div class="sometext">
						<span class="col-orange">现金收银输入9，银联收银输入8然后确定</span>
					</div>
					<input type="text" class="form-control autofildin" id="someinputPay" placeholder=""  onkeyup="doCashPay2();">
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" onclick="doCashPay();">确定</button>
					<button type="button" class="btn btn-white" onclick="doCancel();"data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>

	<!--手机号验证 -->
	<div class="modal inmodal fade" id="popId" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<input type="hidden" id="phone_code">
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h4 class="modal-title" style="font-size:16px;">请输入手机验证码</h4>
				</div>
				<div class="modal-body">
					<div class="input-group">
						<input type="text" class="form-control" placeholder="请输入验证码" id="phone_reCode"> <span class="input-group-btn">
					<button type="button" class="btn btn-jlorange "  onclick="checkPhoneCode()">确定</button> </span>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--等待用户验证 -->
	<div class="modal inmodal fade" id="yzUserCode" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content" style="margin-top:40%;">
				<div class="modal-header">
					<%--<input type="hidden" id="phone_code">--%>
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h4 class="modal-title" style="font-size:16px;">需要用户输入支付密码</h4>
				</div>
				<div class="modal-body">
					<div class="text-center">
						<%--<input type="text" class="form-control" placeholder="请输入验证码" id="phone_reCode"> <span class="input-group-btn">--%>
					<button type="button" class="btn btn-jlorange " style="text-align:center"  onclick="checkPay()">确定</button> </span>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="modal inmodal" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn" style="width:1000px;margin-left:-220px;">
				<div class="modal-header" style="padding:15px;">
					<span style="font-size:18px;">销售统计</span>
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				</div>
				<div class="col-sm-12 modal-body padding0">
					<div class=" saleSel">
						<div class="form-group">
							<label class="control-label toplabel">收银员
								<select class="form-control topselect" id="clerkList" onchange="saleSum()">
								</select>
							</label>
						</div>
					</div>
					<div id="" class="">
						<div class="container newhomeplus">
							<div class="row">
								<div class="col-md-3 col-xs-3 saleTJ">
									<div class="col-sm-12 saleTJlie">
										<div class="col-sm-4">
											<img src="${pageContext.request.contextPath}/resources/plugins/h+/img/xstj-fqze.png"/>
										</div>
										<div class="col-sm-8 text-right">
											<p>发券总额</p>
											<p class="num" id="giveCoupons">0.00</p>
										</div>
									</div>
								</div>
								<div class="col-md-3 col-xs-3 saleTJ">
									<div class="col-sm-12 saleTJlie">
										<div class="col-sm-4">
											<img src="${pageContext.request.contextPath}/resources/plugins/h+/img/xstj-fqbs.png"/>
										</div>
										<div class="col-sm-8 text-right">
											<p >发券笔数</p>
											<p class="num" id="giveCount">0.00</p>
										</div>
									</div>
								</div>
								<div class="col-md-3 col-xs-3 saleTJ">
									<div class="col-sm-12 saleTJlie">
										<div class="col-sm-4">
											<img src="${pageContext.request.contextPath}/resources/plugins/h+/img/xstj-zqze.png"/>
										</div>
										<div class="col-sm-8 text-right">
											<p>兑券总额</p>
											<p class="num" id="payCoupons">0.00</p>
										</div>
									</div>
								</div>
								<div class="col-md-3 col-xs-3 saleTJ">
									<div class="col-sm-12 saleTJlie">
										<div class="col-sm-4">
											<img src="${pageContext.request.contextPath}/resources/plugins/h+/img/xstj-fwfje.png"/>
										</div>
										<div class="col-sm-8 text-right">
											<p>服务费总额</p>
											<p class="num" id="serviceMoney">0.00</p>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-md-12 padding07">
						<div class="" style="">
							<table class="TJtable">
								<tr>
									<td class="bg">现金支付</td>
									<td id="cashPayTotal">0.00</td>
								</tr>
								<tr>
									<td class="bg">微信支付</td>
									<td id="wxPayTotal">0.00</td>
								</tr>
								<tr>
									<td class="bg">支付宝支付</td>
									<td id="aliPayTotal">0.00</td>
								</tr>
								<tr>
									<td class="bg">银行卡支付</td>
									<td id="unionPayTotal">0.00</td>
								</tr>
								<table>
									<table class="TJtable">
										<tr>
											<td class="bg">久零贝</td>
											<td id="coinPayTotal">0.00</td>
										</tr>
										<tr>
											<td class="bg">交易笔数</td>
											<td id="tradeCount">0</td>
										</tr>
										<tr>
											<td class="bg">退款笔数</td>
											<td id="backCount">0</td>
										</tr>
										<table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>


	<!--余额不足是否需要发券 -->
	<div class="modal inmodal fade" id="modal6" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content" style="margin-top:40%;">
				<div class="modal-header">
					<%--<input type="hidden" id="phone_code">--%>
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h4 class="modal-title" style="font-size:16px;" id="modal6Title"></h4>
				</div>
				<div class="modal-body">
					<div class="text-center">
						<button type="button" class="btn btn-primary" style="text-align:center"  onclick="showGift()">充值</button> </span>
						<button type="button" class="btn btn-primary " style="text-align:center"  onclick="closeModal6()">确定</button> </span>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="modal inmodal" id="myModal4" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<span style="font-size:18px;">发券</span>
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
				</div>
				<div class="col-sm-12 modal-body" style="min-height:300px">
					<form class="form-horizontal" name="">
						<div class="col-sm-4" >
							<img src="" id="gift_img">
						</div>
						<div class="col-sm-8">
							<div class="col-sm-12 form-group">
								<label class="col-sm-3 control-label">金额</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="gift_total">
								</div>
							</div>
							<div class="col-sm-12 form-group">
								<label class="col-sm-3 control-label">模式</label>
								<div class="col-sm-9">
									<select class="form-control" id="gift_type">
										<option value="0">默认</option>
										<option value="1">2%</option>
										<option value="2">5%</option>
									</select>
								</div>
							</div>
							<div class="col-sm-12 form-group">
								<label class="col-sm-3 control-label">卡号</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="gift_code">
								</div>
							</div>
							<div class="col-sm-12 form-group">
								<label class="col-sm-3 control-label">备注</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="gift_memo">
								</div>
							</div>
							<div class="col-sm-12 form-group text-center">
								<button class="btn btn-jlorange" type="button" onclick="proGift()">生成久零券</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>


	<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/jeditable/jquery.jeditable.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
	<script src="${ctxStatic}/plugins/h+/js/plugins/iCheck/icheck.min.js"></script>
	<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>
	<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script>
//        $(document).ready(function(){$(".dataTables-example").dataTable();var oTable=$("#editable").dataTable();oTable.$("td").editable("../example_ajax.php",{"callback":function(sValue,y){var aPos=oTable.fnGetPosition(this);oTable.fnUpdate(sValue,aPos[0],aPos[1])},"submitdata":function(value,settings){return{"row_id":this.parentNode.getAttribute("id"),"column":oTable.fnGetPosition(this)[2]}},"width":"90%","height":"100%"})});function fnClickAddRow(){$("#editable").dataTable().fnAddData(["Custom row","New row","New row","New row","New row"])};
    </script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>

	<script>
		var orderCode = "";//订单号
		var isCoinPay = "1";//优先使用久零贝
		var codeCount="0";//判断验证码输入次数
        $(function () {
            loadClerk();
        });

		$(document).keypress(function(e) {
			// 回车键事件
			if(e.which == 13) {
				var code = $("#thisCode").val();
				$("#thisCode").val('');
				if(code != '' )
				{
					toAddCode(code);
				}
			}
		});



        //加载收银员
        function loadClerk(){
            $.ajax( {
                url:'${pageContext.request.contextPath}/api/QTClerk/QTqueryClerk.ac',// 跳转到 action
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    var list=data.return_data;
                    var html='<option value="-1">全部</option>';
                    for(var i=0;i<list.length;i++){
                        html+='<option value="'+list[i].user_code+'">'+list[i].personName+'</option>';
                    }
                    $("#clerkList").html(html);
                    saleSum();
                }
            });

        }

        function toSumInfo() {
            $("#myModal5").modal('show');
        }


		//根据code 获取商品信息
		function toAddCode(code)
		{
			$.ajax({
				url : '${pageContext.request.contextPath}/qtGoods/getGoodsDetailByCode.ac?code='+code,
				type :'post',
				async:false,
				dataType:'json',
				success: function(data){
					var param = JSON.parse(data);
//					alert(param.resultCode);?
					if(param.resultCode == '6')
					{
						if($("#"+param.id).val() != undefined &&  $("#"+param.id).val() != null && $("#"+param.id).val() != '')
						{
							$("#goodsCount_"+param.id).html(parseInt(parseInt($("#goodsCount_"+param.id).html())+1));
							$("#goodsPriceThis_"+param.id).html((parseFloat(parseInt($("#goodsCount_"+param.id).html())*parseFloat($("#goodsPrice_"+param.id).html()))).toFixed(2));
						}else{
							var html ='<tr class="gradeX">'+
									'<input type="hidden" name="goodsId" id="'+param.id+'" value="'+param.id+'">'+
									'<input type="hidden"  id="goodsId_'+param.id+'" value="'+param.goodsId+'">'+
                                '<input type="hidden"  id="goodsStockId_'+param.id+'" value="'+param.id+'">'+
                                '<input type="hidden"  id="whareHouseId_'+param.id+'" value="'+param.whareId+'">'+
									'						<td><span >'+code+'</span></td>'+
									'						<td><span id="goodsName_'+param.id+'">'+param.name+'</span></td>'+
									'						<td><span id="goodsStockName_'+param.id+'">'+(param.firstName!=undefined?param.firstName:"")+' '+(param.secondName!=undefined?param.secondName:"")+' '+(param.thirdName!=undefined?param.thirdName:"")+'</span></td>'+
									'						<td><span id="goodsUnit_'+param.id+'">'+param.unit+'</span></td>'+
									'						<td><span id="goodsPrice_'+param.id+'">'+param.price+'</span></td>'+
									'						<td><span id="goodsCount_'+param.id+'">'+1+'</span></td>'+
									'						<td ><span name="priceOfThis" id="goodsPriceThis_'+param.id+'">'+param.price+'</span></td>'+
									'						<td><a href="javascript:;" onclick="doDel(this);" class="delcur" >删除</a></td>'+
									'					</tr>';
							$("#goodsBody").append(html);
						}
					}else{
						alert(param.resultMsg)
					}
				}
			});
			caculatMone();
			document.getElementById("thisCode").focus();
		}

		function caculatMone()
		{
			var total = 0.00;
			$("span[name=priceOfThis]").each(function(){
				total = (parseFloat(total)+parseFloat(toDecimal2($(this).html()))).toFixed(2);
			});
			$("#totalPay").html(total);
		}

		function toDecimal2(x) {
			var f = parseFloat(x);
			if (isNaN(f)) {
				return 0.00;
			}
			var f = Math.round(x * 100) / 100;
			var s = f.toString();
			var rs = s.indexOf('.');
			if (rs < 0) {
				rs = s.length;
				s += '.';
			}
			while (s.length <= rs + 2) {
				s += '0';
			}
			return s;
		}


		function doDel(obj)
		{
			if(confirm("确定要删除吗?")){
				$(obj).parents("tr").remove();
			}
			caculatMone();
		}



		function somepop(){
			//回车键
			var totalString= parseFloat($("#totalPay").html());
			if(totalString<=0){
				$("#nummoney_input").val("0");
				return ;
			}
			$("#somethingpop").modal('show');

				inputButtenfocus(2);//聚焦
		}

	function payCash()
	{
		window.location.href = "${ctx}/QT/loginQT/toIndex.ac";

	}

	function doPay()
	{
		var couponTotal=parseFloat($("#totalPay").html());
		if(couponTotal > 0)
		{
			somepop();
		}else{
			alert("请先添加商品！");
		}

	}


	//验证付款码
	function phoneValidate(){
		var code = event.keyCode;
		if(code == 13){
			ValidateUser();
		}
	}



	function ValidateUser(){


		var only_code=$("#someinput").val();
		var total=parseFloat($("#totalPay").html());
		var iscoin=1;//0 true 使用 勾上  ,1 false 不使用 未挂钩

		var msgpd="";
		var pd=true;
		if(isNullOrEmpty(only_code)){
			pd=false;
			msgpd="请填写付款码";
		}
		if(total<=0){
			pd=false;
			msgpd="金额不能小于等于0";
		}
		if(!pd){
			alert(msgpd);
			return;
		}

		if ($("#isBicheckbox").get(0).checked) {
			iscoin=0;
		}
        var object = new Object();
        var params=[];
		$("input[name=goodsId]").each(function() {
			var obj={};
			var id = $(this).val();
			obj['goodsStockId'] = $("#goodsStockId_"+id).val();
			obj['goodsName'] = $("#goodsName_"+id).html();
			obj['goodsStockName'] = $("#goodsStockName_"+id).html();
			obj['goodsUnit'] = $("#goodsUnit_"+id).html();
			obj['goodsPrice'] = $("#goodsPrice_"+id).html();
			obj['goodsCount'] = $("#goodsCount_"+id).html();
			obj['goodsPriceThis'] = $("#goodsPriceThis_"+id).html();
			obj['goodsId'] = $("#goodsId_"+id).val();
			obj['onlyCode'] =  only_code;
            obj['whareHouseId'] = $("#whareHouseId_"+id).val();

			params.push(obj);
		});
        object.goodsArry=params;
		var str = encodeURI(JSON.stringify(object));

		$.ajax( {
			url:'${pageContext.request.contextPath}/qtGoods/toValidateUser.ac',// 跳转到 action
			data:{
				only_code :only_code,
				total:total,
				iscoin:iscoin,
				json: str
			},
			type:'post',
			cache:false,
			dataType:'json',
			success:function(data) {
				if(data.error_code){
					//接口调用成功
					var return_code=data.return_code;
					if(return_code=="1"){
						//验证成功
						if(data.return_type=="1") {
						    //如果是付款码支付
                            $("#needMoney").html(data.needMoney);
                            $("#somethingpop").modal('hide');//隐藏扫码页面
                            $("#somethingpop_payOrder").modal('show');//显示付款页面
                            inputButtenfocus(3);
                        }else {
							//手机号支付
                            $("#needMoney").html(data.needMoney);
                            $("#somethingpop").modal('hide');//隐藏扫码页面
							$("#phone_code").val(data.phone_code);//手机验证码
                            $("#phone_reCode").val("");
							$("#popId").modal('show');//手机号验证

                        }
					}else{
                        if(data.msg.indexOf("用户久零券余额不足")!=-1){
                            $("#modal6Title").html(data.msg);
                            $("#modal6").modal('show');
                        }else {
                            alert(data.msg);
                        }
					}
				}else{
					//接口调用失败
					alert(data.msg);
				}
			},
			error : function() {
				alert("异常！");
			}
		});

	}
//判断手机验证码是否正确
		function checkPhoneCode() {
			var reCode=$("#phone_reCode").val();
			var code=$("#phone_code").val();
			if(reCode==null||reCode==""){
				alert("验证码不能为空");
			}else if(reCode!=code){
				codeCount++;
				if(codeCount>=3){
                    $("#popId").modal('hide');//手机号验证
					alert("错误次数过多，请重试");
				}else{
                    alert("验证码不正确");
				}
			}else{
                $("#popId").modal('hide');
                $("#somethingpop_payOrder").modal('show');//显示付款页面
                inputButtenfocus(3);
                codeCount=0;
			}
        }
	
	

	// 判断各种浏览器，找到正确的方法
	function launchFullscreen(element) {
		if(element.requestFullscreen) {
			element.requestFullscreen();
		} else if(element.mozRequestFullScreen) {
			element.mozRequestFullScreen();
		} else if(element.webkitRequestFullscreen) {
			element.webkitRequestFullscreen();
		}
		$("#launch").hide();
		$("#exit").show();
	}

        //退出全屏
        function exitFullscreen(element) {
            if(element.exitFullscreen) {
                element.exitFullscreen();
            }else if(element.mozCancelFullScreen) { //兼容moz
                element.mozCancelFullScreen();
            }else if(element.webkitExitFullscreen) { //兼容webkit
                element.webkitCancelFullScreen();
            }
            $("#launch").show();
            $("#exit").hide();
        }


		//是否是数字或者小数，只能精确到小数点后两位
		//true :合法 false：不合法
		function pdNmuber(num){
			var pdmuber=true;
			if(!isNaN(num)){
				var dot = num.indexOf(".");
				if(dot != -1){
					var dotCnt = num.substring(dot+1,num.length);
					if(dotCnt.length > 2){
						alert("小数位已超过2位");
						pdmuber=false;
					}
				}
			}else{
				alert("数字不合法");
				pdmuber=false;
			}
			return pdmuber;
		}

		//聚焦 (1:金额输入框聚焦,2:付款码扫描聚焦,3:付款界面,去掉聚焦)
		function inputButtenfocus(type){
			if(type==1){
//				document.getElementById("thisCode").focus();
				window.setTimeout("$('#thisCode').focus();", 500);
			}else if(type==2){
				$("#someinput").val("");

				window.setTimeout("$('#someinput').focus();", 500);
			}else if(type==3)
			{
				$("#someinputPay").val("");
//				$("#someinputPay").focus();
				window.setTimeout("$('#someinputPay').focus();", 500);

			}
		}



	//true:是空 false:不为空
	function isNullOrEmpty(strVal) {
		if (strVal == null || strVal == undefined || strVal == '' || strVal == 'undefined' || strVal == 'null' || strVal == 'NULL') {
			return true;
		} else {
			return false;
		}
	}

	//切换久零贝支付选项
	function doCheckThis(obj)
	{
		if($(obj).prop("checked"))
		{
			isCoinPay = "1";
		}else{
			isCoinPay = "2";
		}
	}

	//收银开始
		function doCashPay()
		{
            var object = new Object();
            var only_code=$("#someinput").val();
            var params=[];
            object.onlyCode=only_code;
            $("input[name=goodsId]").each(function() {
                var obj={};
                var id = $(this).val();
                obj['goodsStockId'] = $("#goodsStockId_"+id).val();
                obj['goodsName'] = $("#goodsName_"+id).html();
                obj['goodsStockName'] = $("#goodsStockName_"+id).html();
                obj['goodsUnit'] = $("#goodsUnit_"+id).html();
                obj['goodsPrice'] = $("#goodsPrice_"+id).html();
                obj['goodsCount'] = $("#goodsCount_"+id).html();
                obj['goodsPriceThis'] = $("#goodsPriceThis_"+id).html();
                obj['goodsId'] = $("#goodsId_"+id).val();
                obj['onlyCode'] =  only_code;
                obj['whareHouseId'] = $("#whareHouseId_"+id).val();

                params.push(obj);
            });
            object.goodsArry=params;
            var user_code=$("#user_code").val();
            object.userCode=user_code;
            var str = encodeURI(JSON.stringify(object));
			var userPayCode = $("#someinputPay").val();
			if(userPayCode == null || userPayCode == '')
			{
				alert("请扫支付码！");
			}else {
				if(userPayCode.substr(0, 1) == '1' || userPayCode.substr(0, 1) == '2' || userPayCode.substr(0, 1) == '9' || userPayCode.substr(0, 1) == '8'){

					$.ajax({
						url:'${pageContext.request.contextPath}/qtGoods/toDoGoodPay.ac',
						type:'post',
						data:{
							isCoinPay : isCoinPay,
                            str : str,
							userPayCode :userPayCode,
							type:2,
							onlyCode:only_code
						},
						cache:false,
						dataType:'json',
						success:function(data)
						{
							if(data.return_code == '1'){
                                $("#somethingpop_payOrder").modal('hide');//显示付款页面
                                    alert("支付成功");
                                    window.location.reload();
							}else{
							    if(data.return_info!=null&&data.return_info.indexOf("USERPAYING-")>=0){
                                    orderCode=data.orderMainId;
									$("#phone_code").modal("hide");
							        $("#yzUserCode").modal('show');
                                }else{
                                    alert(data.msg);
                                }
							}
						}
					});
				}else{
					alert("未知的支付方式！");
				}
			}
		}

		//onkeyUp事件支付
		function doCashPay2(){
            var code = event.keyCode;
            if(code == 13){
                doCashPay();
            }
		}


		function doCancel()
		{
			inputButtenfocus(1);
		}


		function toMoeny(){
			showPopup("/QTMain/toMoney.ac","收银记录");
		}


		function  toClerk() {
			<%--window.location.href = "${ctx}/QTClerk/QTtoClerk.ac"--%>
			var url = '${ctx}/api/QTClerk/QTtoClerk.ac';
			//自定页
			parent.layer.open({
				type: 2,
				shift:4,//动画类型
				moveType:1,
				maxmin: true,
				shadeClose: true, //开启遮罩关闭
				area: ['850px', '530px'],
				content: url,
				title : "收营员管理",
				success: function(layero, index){

				},
				cancel: function(index){
//                        $table.bootstrapTable('refresh', queryParams);
//                        return true;
				},
				close  : function(index){
//                        $table.bootstrapTable('refresh', queryParams);
				}
			});
		}



		function toReceipt() {
			showPopup("/QTMain/toReceipt.ac","补打小票");
		}


		function toQuan(){
			showPopup("/QTMain/toQuan.ac","发券记录");
		}


		function showPWDChangePopup(){
			var url = '${ctx}/QTMain/toQTEditPwd.ac';
			//自定页
			parent.layer.open({
				type: 2,
				shift:4,//动画类型
				moveType:1,
				maxmin: true,
				shadeClose: true, //开启遮罩关闭
				area: ['850px', '530px'],
				content: url,
				title : "修改密码",
				success: function(layero, index){

				},
				cancel: function(index){
//                        $table.bootstrapTable('refresh', queryParams);
//                        return true;
				},
				close  : function(index){
//                        $table.bootstrapTable('refresh', queryParams);
				}
			});
		}


		function showAbout90Popup(){

			var url = '${ctx}/jsp/QT/main/about90.jsp';
			//自定页
			parent.layer.open({
				type: 2,
				shift:4,//动画类型
				moveType:1,
				maxmin: true,
				shadeClose: true, //开启遮罩关闭
				area: ['850px', '530px'],
				content: url,
				title : "修改密码",
				success: function(layero, index){

				},
				cancel: function(index){
//                        $table.bootstrapTable('refresh', queryParams);
//                        return true;
				},
				close  : function(index){
//                        $table.bootstrapTable('refresh', queryParams);
				}
			});
		}


		function showPopup(urlSuffix,title){
			var url = '${pageContext.request.contextPath}' + urlSuffix;
			//自定页
			parent.layer.open({
				type: 2,
				shift:4,//动画类型
				moveType:1,
				maxmin: true,
				shadeClose: true, //开启遮罩关闭
				area: ['850px', '530px'],
				content: url,
				title : title,
				success: function(layero, index){

				},
				cancel: function(index){
//                        $table.bootstrapTable('refresh', queryParams);
//                        return true;
				},
				close  : function(index){
//                        $table.bootstrapTable('refresh', queryParams);
				}
			});
		}

		function showother(){
			$('#other').modal('show');
		}


        //判断用户是否付款
        function checkPay() {
            var only_code=$("#someinput").val();
            $.ajax({
                url:'${pageContext.request.contextPath}/qtGoods/checkPay.ac',
                type:'post',
                data:{
                    onlyCode:only_code,
                    orderCode:orderCode
                },
                cache:false,
                dataType:'json',
                success:function(data)
                {
                    if(data.return_code=="1"){
						alert("付款成功！");
                        $("#yzUserCode").modal('hide');
                        window.location.reload();//刷新当前页面.
                    }else{
						alert(data.msg);
                    }
                }
            });
        }

        //退出
        function logout(){
            swal({title: "亲 确定退出本系统吗?",
                    text: "确定后 您将到系统登录页面!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定",
                    cancelButtonText:"取消",
                    closeOnConfirm: false },
                function(){
                    window.location.href="${ctx}/QTMain/toLogOut.ac";
                });
        }


        //加载销售统计
        function saleSum() {
            $("#giveCoupons").html("");
            $("#giveCount").html("");
            $("#payCoupons").html("");
            $("#serviceMoney").html("");
            $("#cashPayTotal").html("");
            $("#wxPayTotal").html("");
            $("#aliPayTotal").html("");
            $("#unionPayTotal").html("");
            $("#coinPayTotal").html("");
            $("#tradeCount").html("");
            $("#backCount").html("");
            var id=$("#clerkList").val();
            $.ajax({
                url:'${pageContext.request.contextPath}/qtGoods/saleSum.ac',
                type:'post',
                data:{
                    id:id
                },
                cache:false,
                dataType:'json',
                success:function(data)
                {
                    if(data.return_code=="1"){
                        $("#giveCoupons").html(data.return_data[0].giveCoupons);
                        $("#giveCount").html(data.return_data[0].giveCount);
                        $("#payCoupons").html(data.return_data[0].payCoupons);
                        $("#serviceMoney").html(data.return_data[0].serviceMoney);
                        $("#cashPayTotal").html(data.return_data[0].cashPayTotal);
                        $("#wxPayTotal").html(data.return_data[0].wxPayTotal);
                        $("#aliPayTotal").html(data.return_data[0].aliPayTotal);
                        $("#unionPayTotal").html(data.return_data[0].unionPayTotal);
                        $("#coinPayTotal").html(data.return_data[0].coinPayTotal);
                        $("#tradeCount").html(data.return_data[0].tradeCount);
                        $("#backCount").html(data.return_data[0].backCount);
                    }else{
                        alert(data.return_info);
                    }
                }
            });
        }

        //发券
        function showGift() {
            $('#gift_img').attr("src","");
            $("#gift_total").val("");
            $("#gift_type").val("0");
            $("#gift_code").val("");
            $("#gift_memo").val("");
            $("#myModal4").modal('show');
            $("#modal6").modal('hide');
        }

        function closeModal6() {
            window.location.reload();
        }

        //生成二维码
        function proGift() {
            var gift_total=$("#gift_total").val();
            var gift_type=$("#gift_type").val();
            var gift_card=$("#gift_code").val();
            var gift_memo=$("#gift_memo").val();
            if(isNullOrEmpty(gift_total)){
                alert("请填写金额");
            }else{
                $.ajax( {
                    url:'${pageContext.request.contextPath}/qtGoods/proGift.ac',// 跳转到 action
                    data:{
                        gift_total :gift_total,
                        gift_type:gift_type,
                        gift_card:gift_card,
                        gift_memo: gift_memo
                    },
                    type:'post',
                    cache:false,
                    dataType:'json',
                    success:function(data) {
                        if(data.return_code=="1"){
                            $("#gift_img").attr("src",data.return_info);
                        }else{
                            alert(data.return_info);
                        }
                    },
                    error : function() {
                        alert("异常！");
                    }
                });
            }
        }
	</script>


</body>

</html>